import RPi.GPIO as gpio
import time

# BCM port number
# With Board number: 27, 28, 29
DIO=16
RCLK=20
SCLK=21

# number coding 
#// 0	 1	  2	   3	4	 5	  6	   7	8	 9	  A	   b	C    d	  E    F    -
#0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x8C,0xBF,0xC6,0xA1,0x86,0xFF,0xbf

def init():
    gpio.setwarnings(False)
    gpio.setmode(gpio.BCM)

    gpio.setup(DIO, gpio.OUT)
    gpio.setup(RCLK, gpio.OUT)
    gpio.setup(SCLK, gpio.OUT)


def sendRCLK():
    gpio.output(RCLK, gpio.LOW)
    gpio.output(RCLK, gpio.HIGH)


def sendSCLK():
    gpio.output(SCLK, gpio.LOW)
    gpio.output(SCLK, gpio.HIGH)


def ledOut(number):
    #print ("send %x in led_out" % number)
    for i in range(8, 0, -1):
        if number & 0x80:
            #print ("DIO.high")
            gpio.output(DIO, gpio.HIGH)
        else:
            #print ("DIO.low")
            gpio.output(DIO, gpio.LOW)

        number = number << 1

        sendSCLK()

def sle():
    pass
    #time.sleep(0.05)

def display():
    ledOut(0xF9)
    ledOut(0x01)
    sendRCLK()

    ledOut(0xA4)
    ledOut(0x02)
    sendRCLK()

    ledOut(0xB0)
    ledOut(0x04)
    sendRCLK()

    ledOut(0x99)
    ledOut(0x08)
    sendRCLK()

def main():
    init()

    while True:
        display()

    gpio.cleanup()

main()


